﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;

namespace TradeTest
{
    public partial class FormOutCS : Form
    {
        public FormOutCS(string path)
        {
            InitializeComponent();

            richTextBox1.Text = ShowXml(path);
        }

        /// <summary>
        /// XML格式化为文本显示
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string ShowXml(string path)
        {
            MemoryStream mstream = new MemoryStream();
            XmlTextWriter writer = new XmlTextWriter(mstream, null);
            XmlDocument xmldoc = new XmlDocument();
            writer.Formatting = Formatting.Indented;

            xmldoc.LoadXml(File.ReadAllText(path));
            xmldoc.WriteTo(writer);
            writer.Flush();
            writer.Close();

            string strReturn = Encoding.UTF8.GetString(mstream.ToArray());
            mstream.Close();
            return strReturn;
        }
    }
}
